package LeetCode.month02.day54;

import java.util.ArrayList;
import java.util.List;

public class No173 {

}
class BSTIterator {
    List<TreeNode> list = new ArrayList<>();
    int index;

    public BSTIterator(TreeNode root) {
        getNode(root);
        index = 0;
    }

    public int next() {
        return list.get(index++).val;
    }

    public boolean hasNext() {
        return index<list.size();
    }

    public TreeNode getNode(TreeNode root){
        if(root==null) return root;
        getNode(root.left);
        list.add(root);
        getNode(root.right);
        return root;
    }



    public static void main(String[] args) {
        TreeNode root = new TreeNode(7);
        root.left = new TreeNode(3);
        root.right = new TreeNode(15);
        root.right.left = new TreeNode(9);
        root.right.right = new TreeNode(20);
        BSTIterator bi = new BSTIterator(root);
        System.out.println(bi.list);
        System.out.println(bi.next());
        System.out.println(bi.next());


    }
}
